<?php
/**
	素材详情页的下载 充值 按钮
**/
require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(DEDEINC."/memberlogin.class.php");

$ml = new MemberLogin();
$muid = $ml->M_ID;

$jbmc = "金币";//虚拟币名称等于金币

/******************************************下载 dows******************************************/

$dowurl = "$cfg_phpurl/download.php?open=0&aid=$aid";//转换获取下载地址

$arc = $dsql->GetOne("select * from #@__addonsoft where aid='$aid'");//查询模板所需要的金币
$needmoney = $arc['needmoney'];
$zhneedmoney = $needmoney;

$money = $dsql->GetOne("select * from #@__member where mid='$muid'");//查询会员所拥有的金币
$money = $money['money'];

$at = $dsql->GetOne("select * from #@__archives where id='$aid'");//查询主表

//下载后剩余金币
$dmoney = $money - $needmoney;



//收藏按钮

$s = $dsql->GetOne("select * from #@__member_stow where aid='$aid' and mid='$ml->M_ID'");
if(($aid==$s['aid'])&& ($muid!=0))
{
   echo "document.getElementById('stows').innerHTML=\"<a onclick='cancel()' class='sta-site'><i class='icon-fav'></i>&nbsp;<font>已收藏</font></a><input type='hidden' name='id' value='$aid' />\";";
}
elseif($muid!=0)
{
	echo "document.getElementById('stows').innerHTML=\"<a onclick='stows()' class='sta-site'><i class='icon-fav'></i>&nbsp;<font>收藏</font></a><input type='hidden' name='id' value='$aid' />\";";
}else{
	echo "document.getElementById('stows').innerHTML=\"<a id='loginBtn' class='sta-site plogin'><i class='icon-fav'></i>&nbsp;<font>收藏</font></a>\";";
}

//如果是免费素材
if($needmoney==0 && $muid!=0)
{
	echo "document.getElementById('dmsgtitle').innerHTML=\"下载".$at['title']."\";";
	echo "document.getElementById('dowmsg').innerHTML=\"<p><span class='float_l'>该素材为免费资源，请下载</span></p>\";";
	echo "document.getElementById('popsub').innerHTML=\"<div class='pop-sub'><a id='dow' href='".$dowurl."' target='_blank' class='popup-ok'>免费下载</a><a class='popup-close'>取消</a></div>\";";
}

//如果是管理员
else if($ml->isAdmin==1)
{
	echo "document.getElementById('dmsgtitle').innerHTML=\"下载".$at['title']."\";";
	echo "document.getElementById('dowmsg').innerHTML=\"<p><span class='float_l'>您是管理员，享免费特权</span></p>\";";
	echo "document.getElementById('popsub').innerHTML=\"<div class='pop-sub'><a id='dow' href='".$dowurl."' target='_blank' class='popup-ok'>免费下载</a><a class='popup-close'>取消</a></div>\";";
}

//如果是该资源的作者
elseif($wid==$muid)
{
	echo "document.getElementById('dmsgtitle').innerHTML=\"下载".$at['title']."\";";
	echo "document.getElementById('dowmsg').innerHTML=\"<p><span class='float_l'>您是该资源的作者，享免费特权</span></p>\";";
	echo "document.getElementById('popsub').innerHTML=\"<div class='pop-sub'><a id='dow' href='".$dowurl."' target='_blank' class='popup-ok'>免费下载</a><a class='popup-close'>取消</a></div>\";";
}
//如果会员已经登录
if($muid != '0')
{
	$d = $dsql->GetOne("select mid from #@__member_operation where buyid='ARCHIVE".$aid."' And mid='$muid'");
	//如果没有下载过
	if($d['mid'] != $muid)
	{
		//如果金币不足 显示充值按钮
		if($money < $needmoney)
		{
			echo "document.getElementById('dowmsg').innerHTML=\"<p><span class='float_l'>您的余额</span><span class='float_r'>".$money."<i>$jbmc</i></span></p><p><span class='float_l'>下载需要</span><span class='float_r'><b>".$needmoney."</b><i>$jbmc</i></span></p><p><span class='float_l'>下载后余额</span><span class='float_r'>余额不足，请先充值！</span></p>\";";
			echo "document.getElementById('popsub').innerHTML=\"<div class='pop-sub'><a id='dow' href='".$cfg_memberurl."/buy.php' class='popup-ok' target='_blank'>在线充值</a></div>\";";
		} else {
            //金币足够本次下载 直接显示下载
			echo "document.getElementById('dowmsg').innerHTML=\"<p><span class='float_l'>您的余额</span><span class='float_r'>".$money."<i>$jbmc</i></span></p><p><span class='float_l'>下载需要</span><span class='float_r'><b>".$needmoney."</b><i>$jbmc</i></span></p><p><span class='float_l'>下载后余额</span><span class='float_r'>$dmoney<i>$jbmc</i></span></p>\";";
			echo "document.getElementById('popsub').innerHTML=\"<div class='pop-sub'><a id='dow' href='".$dowurl."'  class='popup-ok'>确认支付</a><a class='popup-close'>取消</a></div>\";";
		}
	} else {
        //如果有下载过 则提示不重复扣费
        echo "document.getElementById('dowmsg').innerHTML=\"<p><span class='float_l'>您已经购买过该素材，享免费特权</span></p>\";";
		echo "document.getElementById('popsub').innerHTML=\"<div class='pop-sub'><a id='dow' href='".$dowurl."' class='popup-ok'>免费下载</a><a class='popup-close'>取消</a></div>\";";
	}	
	echo "document.getElementById('dmsgtitle').innerHTML=\"下载".$at['title']."\";";
	
	echo "document.getElementById('download').innerHTML=\"<a data-pop='pop-dows' class='sta-site' href='#'><div style='width:100%'><i class='icon-down'></i>下载素材</div></a>\";";
}

//如果没有登录 点击登录按钮弹出请登录提示
else
{
	echo "document.getElementById('download').innerHTML=\"<a id='loginBtn' class='sta-site plogin' href='javascript:void(0);'><i class='icon-down'></i>下载素材</a>\";";

}

$arc = $dsql->GetOne("SELECT title FROM `#@__archives` WHERE id='$aid'");

$mmm = $dsql->GetOne("select userid from #@__member where uname='$w'");

/**管理员给用户发消息***/
if($ml->isAdmin==1)
{
	echo "document.getElementById('twuser').innerHTML=\"<a href='$cfg_memberurl/?uid=".$mmm['userid']."' target='_blank'>TA的空间</a><a data-pop='tor'>发消息</a>\";";
	echo "document.getElementById('towriter').innerHTML=\"<form method='post' action='".$cfg_cmsurl."/i/fankui.php' name='form1'><input type='hidden' name='type' value='wliuyan' /><input type='hidden' name='wid' value='".$wid."' /><input type='hidden' name='arctitle' value='".$arc['title']."' /><div class='login liuyan'><p>请填写您要发送给".$w."的消息内容。</p><ul class='arc-loginlist'><li class='pwd'><input type='text' name='title' class='input' placeholder='标题' required='required' style='width:295px;' value='".$arc['title']."' /></li><li class='uname'><textarea name='wneir' class='srk' placeholder='内容' required='required'></textarea></li></ul></div><div class='pop-sub'><button type='submit' class='popup-ok arc-loginBtn' id='dow'>提交</button></div></form>\";";
}
/**管理员给用户发消息结束**/
?>

